package com.candy.dao.impl;

import com.candy.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Repository(value = "accountDao")
@Scope(value = "singleton")
public class AccountDaoImpl implements AccountDao {
    @Autowired
    JdbcTemplate jdbcTemplate;

//出账
    @Override
    public void outter(String username,int money) {
        String sql="update account SET money=money-"+money+" WHERE accountname='"+username+"';";
        jdbcTemplate.update(sql);

    }
//入账
    @Override
    public void inner(String username,int money) {
        String sql="update account SET money=money+"+money+" WHERE accountname='"+username+"';";
        jdbcTemplate.update(sql);
    }

    @PostConstruct
    public void startMethod(){
        System.out.println("初始化方法");
    }
    @PreDestroy
    public void endMethod(){
        System.out.println("销毁方法");
    }


    public JdbcTemplate getJdbcTemplate() {
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
}
